package auctionClient;

import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac;

public class HMACCreator {
	private Key key;
	private String input;
	
	public HMACCreator(String input, Key key){
		this.input=input;
		this.key=key;
	}


	public byte[] createHashMac(){
		Key secretKey =key;
		byte[] message=input.getBytes();

		byte[] hash;
		
		Mac hMac = null;
		try {
			hMac = Mac.getInstance("HmacSHA256");	
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		try {
			hMac.init(secretKey);	
		} catch (InvalidKeyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// MESSAGE is the message to sign in bytes 
		hMac.update(message);
		hash = hMac.doFinal();
		return hash;
	}
	
	
}
